package com.huawei.spare.part.replace.ssh;

import com.huawei.spare.part.replace.models.Replacement;
import com.huawei.spare.part.replace.utils.SSHHelper;
import net.schmizz.sshj.SSHClient;
import net.schmizz.sshj.common.IOUtils;
import net.schmizz.sshj.connection.channel.direct.Session;

import java.io.Console;
import java.io.IOException;

/**
 * This examples demonstrates how a remote command can be executed.
 */
public class Exec2 {
    private static final Console con = System.console();

    public static void main(String... args)
            throws IOException {
//        final SSHClient ssh = new SSHClient();
//        ssh.addHostKeyVerifier(new PromiscuousVerifier());
//        ssh.connect("112.93.129.107");
//        ssh.authPassword("root", "Admin@7*24");
//        ssh.connect("115.159.160.190");
//        ssh.authPassword("root", "!QAZ2wsx#EDC");


        try (SSHClient ssh = SSHHelper.newSSHClient("112.93.129.107", "hy", "Huawei@1234")) {
            try (final Session session = ssh.startSession()) {
                final Session.Command exec = session.exec("smmget -l swi3:fru2 -d version");
                System.out.println(IOUtils.readFully(exec.getInputStream()).toString());
            }
//            for (int position = 1; position <= 4; position++) { // load slots
//                final Replacement.Slot slot = new Replacement.Slot(position).read(ssh);
//                System.out.println(slot);
//            }
        }
    }

}
